package com.example.admin.controller;



import com.example.admin.service.EmpService;
import com.example.common.result.PageBean;
import com.example.common.result.Result;
import com.example.model.emp.pojo.Employee;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class EmpController{
    @Autowired
    private EmpService empSevice;
    @GetMapping("/admin/emps")
    //page分页查询的页吗 pagesize 每页每条记录数
    //controll中只关于连接前端的代码
    public Result page(Integer page , Integer pageSize, String name, String gender, String position){
        if(page==null){
            page=1;
        }if (pageSize==null){
            pageSize=10;
        }
        PageBean page1 = empSevice.page(page, pageSize, name, gender, position);
        return Result.success(page1);
    }

    @DeleteMapping("/admin/emps/{ids}")
    public Result delete(@PathVariable(required = true) List<Integer> ids){
        empSevice.delete(ids);
        return Result.success();
    }

    @PostMapping("/admin/emps")
    public Result save(@RequestBody Employee employee){
        empSevice.save(employee);
        return Result.success();
    }
    @GetMapping("/admin/emps/{id}")
    public Result selectById(@PathVariable Integer id){
        Employee employee = empSevice.selectById(id);
        return Result.success(employee);
    }
    @PutMapping("/admin/emps")
    public Result updateById(@RequestBody Employee employee){
        empSevice.updateById(employee);
        return Result.success();
    }
}

